<form id="safeModel" class="layui-form-pane layui-form" action="" method="post" style="margin: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" required lay-verify="required" placeholder="请输入新密码"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">二次确认</label>
        <div class="layui-input-block">
            <input type="password" name="repassword" required lay-verify="required" placeholder="请再次输入新密码"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="submit" style="width: 100%" lay-submit lay-filter="formDemo">提交修改</button>
        <style>
            .submit {
                cursor: pointer;
                padding: 8px 15px;
                border: unset;
                border-radius: 15px;
                color: #212121;
                z-index: 1;
                background: #e8e8e8;
                position: relative;
                font-weight: 1000;
                font-size: 17px;
                -webkit-box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
                box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
                transition: all 250ms;
                overflow: hidden;
            }

            .submit::before {
                content: "";
                position: absolute;
                top: 0;
                left: 0;
                height: 100%;
                width: 0;
                border-radius: 15px;
                background-color: #212121;
                z-index: -1;
                -webkit-box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
                box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
                transition: all 250ms
            }

            .submit:hover {
                color: #e8e8e8;
            }

            .submit:hover::before {
                width: 100%;
            }
        </style>
    </div>
</form>
<script>
    layui.use('form', function () {
        const form = layui.form;
        form.on('submit(formDemo)', function (data) {
            if (data.field.password === data.field.repassword) {
                $.ajax({
                    url: '/index/user/safe',
                    method: 'post',
                    data: data.field,
                    success: function (result) {
                        layer.msg(result.msg);
                        if (result.code === 1) {
                            layer.close(safeModel)
                        }
                    }
                })
            }else{
                layer.msg("两次密码不一致")
            }
            return false;
        });
    });
</script>